﻿using System.Data;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;

namespace GUI.Controls.News
{
    public partial class OtherNews : System.Web.UI.UserControl
    {
        private const string LiFormat = "<li><span class=\"liststyle2 sprite fl\"></span><a href=\"{0}\" title=\"{2}\">{1}&nbsp;&nbsp;<span class=\"date\">({3})</span></a></li>";

        public bool DataBind(DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var sb = new System.Text.StringBuilder();
                foreach (DataRow r in dt.Rows)
                {
                    sb.Append(string.Format(
                            LiFormat,
                            r[SqlConstants.NewsPublish.Url],
                            r[SqlConstants.NewsPublish.Title],
                            r[SqlConstants.NewsPublish.EncodedTitle],
                            PresentationUtils.Object2DateTime(r[SqlConstants.NewsPublish.DistributionDate].ToString()).ToString("dd/MM/yyyy HH:mm")
                        ));
                }
                ltrData.Text = sb.ToString();
                return true;
            }

            return false;
        }
    }
}